<?php if(!defined('PUBLIC_DIR')) die('No Access!');

class Log implements iLog{
	private $LogFile;

	public function __construct($file = 'site.log', $path = 'default'){
		if($path === 'default')
			$path = TEMP_DIR . 'Logs' . DS;
		else if(is_dir($path))
			$path = realpath($path) . DS;
		else
			trigger_error('Directory ' . $path . ' not exits!', E_USER_ERROR);
		$this->LogFile = new File($path . $file, True);
	}
	public function Read($_time = null){
		if($_time == NULL)
			return $this->LogFile->ReadLine(-1);
		$temp = $this->LogFile->ReadLines();
		foreach($temp as $nr => $line){
			$lin = split(':@:', $line);
			if($lin[0] == $_time)
				return $line;
		}
		return False;
	}
	public function ReadAll(){
		return $this->LogFile->ReadLines();
	}
	public function Append($_content, $_type = E_USER_NOTICE, $_time = NULL){
		if(!is_int($_time) || $_time == NULL)
			$_time = time();
		return $this->LogFile->AppendLine($_time . ' :#: ' . date('j F, Y, g:i a', $_time) . ' :#: ' . str_replace(':#:', '#', $_content));
	}
	public function Clear(){
		return $this->LogFile->Clear();
	}
}